/******************************************************************************
* File description: ResultProtoCurve.qml
* Function: 实验结果：原始曲线
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-27
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtCharts 2.14

Item {
    id: root

    /* property 定义开始 */
    property int headerLeftMargin: 0

    property bool chartVisible: true // 报表可见性
    property bool tableVisible: true // 表格可见性
    /* property 定义结束 */

    // 容器
    Item {
        id: container
        anchors.fill: parent

        ColumnLayout {
            anchors.fill: parent

            // 头部
            Item {
                id: headerContainer
                Layout.fillWidth: true
                Layout.preferredHeight: 40
                Layout.leftMargin: root.headerLeftMargin

                RowLayout {
                    id: headerRowLayout
                    anchors.fill: parent

                    // 选择器
                    Item {
                        id: selectorCon
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        Layout.alignment: Qt.AlignTop
                        clip: true

                        RowLayout {
                            anchors.fill: parent
                            spacing: 10

                            CustomHorSpacerItem {}

                            // FAM
                            CustomCheckBox {
                                id: famCheck
                                checkBoxText: "FAM"
                                checkWidth: 20
                                checkHeight: 20
                                checkRadius: 2
                                checkedFillColor: "#FFFF2B37"
                                checkBoxFontColor: "#FFFF2B37"
                                checkBorderColor: "#FFF"
                                checkedBorderColor: "transparent"
                                isChecked: true
                            }

                            // VIC
                            CustomCheckBox {
                                id: vicCheck
                                checkBoxText: "VIC"
                                checkWidth: 20
                                checkHeight: 20
                                checkRadius: 2
                                checkedFillColor: "#FF422FCD"
                                checkBoxFontColor: "#FF422FCD"
                                checkBorderColor: "#FFF"
                                checkedBorderColor: "transparent"
                                isChecked: true
                            }

                            // ROX
                            CustomCheckBox {
                                id: roxCheck
                                checkBoxText: "ROX"
                                checkWidth: 20
                                checkHeight: 20
                                checkRadius: 2
                                checkedFillColor: "#FF00C441"
                                checkBoxFontColor: "#FF00C441"
                                checkBorderColor: "#FFF"
                                checkedBorderColor: "transparent"
                                isChecked: true
                            }

                            // CY5
                            CustomCheckBox {
                                id: cy5Check
                                checkBoxText: "CY5"
                                checkWidth: 20
                                checkHeight: 20
                                checkRadius: 2
                                checkedFillColor: "#FFFF873E"
                                checkBoxFontColor: "#FFFF873E"
                                checkBorderColor: "#FFF"
                                checkedBorderColor: "transparent"
                                isChecked: true
                            }

                            CustomHorSpacerItem {}
                        }
                    }

                    // 筛选
                    Item {
                        id: shaixuanCombobox
                        Layout.preferredWidth: 105
                        Layout.fillHeight: true

                        CustomComboBox {
                            anchors.fill: parent
                            comboBgColor: "transparent"
                            comboFontColor: "#FFF"
                            comboBorderColor: "#FFF"
                            comboDefaultText: "筛选"
                            comboFontHorAlign: Text.AlignRight

                            MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    // filterWidgetshow = !filterWidgetshow
                                    shaixuanPopup.opened ? shaixuanPopup.close(): shaixuanPopup.open()
                                }
                            }
                        }

                        // 筛选下拉菜单
                        Popup {
                            id: shaixuanPopup
                            modal: false
                            topPadding: 2
                            padding: 10
                            background: Rectangle {
                                color: "red"
                                visible: false
                            }
                            closePolicy: Popup.NoAutoClose
                            x: -shaixuanPopupContent.width + parent.width - shaixuanPopup.leftPadding
                            y: parent.height
                            clip: true
                            // 打开时动画
                            enter: Transition {
                                NumberAnimation {
                                    property: "height"
                                    from: 0
                                    to: shaixuanPopupContent.height + shaixuanPopup.bottomPadding
                                    duration: 200
                                    easing.type: Easing.InOutQuad
                                }
                            }
                            // 关闭时动画
                            exit: Transition {
                                NumberAnimation {
                                    property: "height"
                                    from: shaixuanPopupContent.height + shaixuanPopup.bottomPadding
                                    to: 0
                                    duration: 200
                                    easing.type: Easing.InOutQuad
                                }
                            }

                            ColumnLayout {
                                anchors.fill: parent

                                FilterWidget {
                                    id: shaixuanPopupContent
                                    Layout.preferredWidth: 588
                                    Layout.preferredHeight: 327
                                }
                            }
                        }
                    }
                }
            }

            // 图表
            Item {
                Layout.fillWidth: true
                Layout.fillHeight: true

                RowLayout {
                    anchors.fill: parent
                    spacing: 6
                    anchors.margins: 0

                    // 报表
                    Rectangle {
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        visible: root.chartVisible
                        color: "#C3FFFFFF"
                        radius: 13

                        ChartView {
                            id: instantChart
                            anchors.fill: parent
                            antialiasing: true
                            legend.visible: false
                            margins.left: 0
                            margins.bottom: 0
                            backgroundColor: "transparent"
                            backgroundRoundness: 0

                            ValueAxis {
                                id: axisX
                                titleText: qsTr("循环数(Cycles)")
                                titleFont.family: "Alibaba PuHuiTi"
                                titleFont.pixelSize: 15
                                labelsFont.family: "Alibaba PuHuiTi"
                                labelsFont.pixelSize: 15
                                labelsColor: "#9A222222"
                                gridLineColor: "#00999999"
                                min: 0
                                max: 40
                                tickCount: 5
                                labelFormat: "%d"
                            }

                            ValueAxis {
                                id: axisY
                                titleText: qsTr("荧光强度(Rn)")
                                titleFont.family: "Alibaba PuHuiTi"
                                titleFont.pixelSize: 15
                                labelsFont.family: "Alibaba PuHuiTi"
                                labelsFont.pixelSize: 15
                                labelsColor: "#9A222222"
                                gridLineColor: "#999"
                                min: 0
                                max: 20000
                                tickCount: 5
                                labelFormat: "%d"
                            }

                            SplineSeries {
                                id: fam
                                axisX: axisX
                                axisY: axisY
                                color: "#FF2B37"
                                XYPoint {x: 0; y: 4000}
                                XYPoint {x: 1; y: 5000}
                                XYPoint {x: 2; y: 8000}
                                XYPoint {x: 3; y: 10000}
                                XYPoint {x: 4; y: 13000}
                                XYPoint {x: 5; y: 15000}
                                XYPoint {x: 6; y: 12000}
                                XYPoint {x: 7; y: 3800}
                                XYPoint {x: 8; y: 4000}
                                XYPoint {x: 9; y: 5600}
                                XYPoint {x: 10; y: 18900}
                                XYPoint {x: 11; y: 4000}
                                XYPoint {x: 12; y: 5000}
                                XYPoint {x: 13; y: 8000}
                                XYPoint {x: 14; y: 10000}
                                XYPoint {x: 15; y: 13000}
                                XYPoint {x: 16; y: 15000}
                                XYPoint {x: 17; y: 12000}
                                XYPoint {x: 18; y: 3800}
                                XYPoint {x: 19; y: 4000}
                                XYPoint {x: 20; y: 5600}
                                XYPoint {x: 21; y: 5600}
                                XYPoint {x: 22; y: 18900}
                                XYPoint {x: 23; y: 4000}
                                XYPoint {x: 24; y: 5000}
                                XYPoint {x: 25; y: 8000}
                                XYPoint {x: 26; y: 10000}
                                XYPoint {x: 27; y: 13000}
                                XYPoint {x: 28; y: 15000}
                                XYPoint {x: 29; y: 12000}
                                XYPoint {x: 30; y: 3800}
                                XYPoint {x: 31; y: 4000}
                                XYPoint {x: 32; y: 5600}
                                XYPoint {x: 33; y: 18900}
                                XYPoint {x: 34; y: 4000}
                                XYPoint {x: 35; y: 5000}
                                XYPoint {x: 36; y: 8000}
                                XYPoint {x: 37; y: 10000}
                                XYPoint {x: 38; y: 13000}
                                XYPoint {x: 39; y: 15000}
                                XYPoint {x: 40; y: 12000}
                            }
                        }
                    }

                    // 缩放部分
                    Item {
                        Layout.fillHeight: true
                        Layout.preferredWidth: rightExtBtn.width

                        ColumnLayout {
                            anchors.fill: parent
                            spacing: 194

                            CustomVerSpacerItem {}

                            // 向右展开
                            BaseButton {
                                id: rightExtBtn
                                Layout.preferredWidth: 26
                                Layout.preferredHeight: 26
                                isSvg: true
                                btnIconPath: "qrc:/icons/left_arrow.svg"
                                btnIconWidth: width
                                btnIconHeight: height
                                btnBorderWidth: 0
                                btnLabelWidth: 0
                                btnLabelHeight: 0
                                btnColor: "transparent"
                                rotation: 180
                                btnIconAlignment: Image.Stretch

                                MouseArea {
                                    anchors.fill: parent
                                    cursorShape: Qt.PointingHandCursor
                                    onClicked: {
                                        // 判断报表有没有隐藏，如果左侧报表隐藏，则让其显示；否则，让右侧表格隐藏
                                        if(!root.chartVisible) {
                                            root.chartVisible = true
                                        }
                                        else {
                                            root.tableVisible = false
                                        }
                                    }
                                }
                            }

                            // 向左展开
                            BaseButton {
                                id: leftExtBtn
                                Layout.preferredWidth: rightExtBtn.width
                                Layout.preferredHeight: rightExtBtn.height
                                isSvg: true
                                btnIconPath: "qrc:/icons/left_arrow.svg"
                                btnIconWidth: width
                                btnIconHeight: height
                                btnBorderWidth: 0
                                btnLabelWidth: 0
                                btnLabelHeight: 0
                                btnColor: "transparent"
                                btnIconAlignment: Image.Stretch

                                MouseArea {
                                    anchors.fill: parent
                                    cursorShape: Qt.PointingHandCursor
                                    onClicked: {
                                        // 判断表格有没有隐藏，如果右侧表格隐藏，则让其显示；否则，让左侧报表隐藏
                                        if(!root.tableVisible) {
                                            root.tableVisible = true
                                        }
                                        else {
                                            root.chartVisible = false
                                        }
                                    }
                                }
                            }

                            CustomVerSpacerItem {}
                        }
                    }

                    // 表格部分
                    ResultTableView {
                        id: protoTable
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        plateColCount: 4
                        visible: root.tableVisible
                        // isHover: !filterWidgetshow
                    }
                }
            }
        }
    }
}
